//package com.safe.app.config.filter;
//
//import com.safe.app.config.ContextHolderUtils;
//import com.safe.app.config.ResultBean;
//import com.safe.app.config.context.ExecutionContext;
//import com.safe.app.config.init.redis.RedisServer;
//import com.safe.app.model.User;
//import com.safe.app.utils.constants.SystemConstant;
//import com.safe.app.utils.exceptions.enums.ErrorMsgEnum;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.StringUtils;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//
///**
// * 登陆信息验证切面
// *
// * @author h2l
// */
//@Aspect
//@Slf4j
//@Component
//public class WebRequestAspect {
//
//    private static final String[] NOT_FILTER = {"/index", "/static"};
//
//    @Autowired
//    private RedisServer redisServer;
//
//    @Around("execution(com.safe.app.config.ResultBean com.safe.app.controller..*(..))")
//    public ResultBean around(JoinPoint joinPoint) throws Throwable {
//        HttpServletRequest request = ContextHolderUtils.getRequest();
//        String requestURI = request.getRequestURI();
//        ProceedingJoinPoint proceedingJoinPoint = (ProceedingJoinPoint) joinPoint;
//
//        for (String notFilterURL : NOT_FILTER) {
//            if (requestURI.contains(notFilterURL)) {
//                return (ResultBean) proceedingJoinPoint.proceed();
//            }
//        }
//        String sessionId = (String) request.getSession().getAttribute(SystemConstant.LOGIN_USER_KEY);
//        if (StringUtils.isBlank(sessionId)) {
//            ExecutionContext.setContextMap(null);
//            return new ResultBean(ErrorMsgEnum.noAuthException, "登陆失效,请重新登陆！");
//        }
//        User user = (User) redisServer.get(SystemConstant.SAFE_APP_SESSION_ID + sessionId);
//        if (user == null) {
//            ExecutionContext.setContextMap(null);
//            return new ResultBean(ErrorMsgEnum.noAuthException, "登陆失效,请重新登陆！");
//        } else {
//            ExecutionContext.setUserId(user.getUserId());
//            ExecutionContext.setLoginUser(user);
//            redisServer.incr(SystemConstant.SAFE_APP_SESSION_ID + sessionId, 60 * 60 * 10);
//        }
//        return (ResultBean) proceedingJoinPoint.proceed();
//    }
//
//}
